home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- ibrowse_il.c - Support for identifying and iconifying ImageVision
- Library image format files, including TIFF, FIT, and future additions.
-
- Tim Heidmann
- Version 1.2.2
- November 30, 1993
- modified for IL 2.3 3/18/94
-
- copyright 1993, Silicon Graphics
- */
-
- #include <il/ilGenericImgFile.h>
- #include <il/ilCdefs.h>
- #include <stdio.h>
- #include <stdlib.h> /* getenv() */
- #include <string.h> /* strcmp() */
- #include "ibrowse.h"
-
- int unThreaded = FALSE;
-
-
- int
- Check_IL(struct iconDirStruct *ids, int fd) {
- /* Check for IL image type file.
- If it is an IL image, set xsize, ysize, zsize.
- Return TRUE iff it is an IL format image file. */
- char name_buf[PATH_MAX];
- ilFileImg *theIlFile;
- char *typeName;
-
- if (strcmp(ids->name, "..") == 0) return FALSE;
- if (strcmp(ids->name, ".") == 0) return FALSE;
-
- /* Defeat multi-threading, which interferes with our UI/reader operation */
- if (!unThreaded) {
- /* Not in libcil.a yet...
- ilMpSetMaxProcs(0, 0);
- */
- putenv("IL_COMPUTE_THREADS=0");
- putenv("IL_SPARE_THREADS=0");
- unThreaded = TRUE;
- }
-
- sprintf(name_buf, "%s/%s", theDirName, ids->name);
- theIlFile = ilOpenImgFile(name_buf, "r");
- if (theIlFile != NULL) {
- ids->xsize = ilGetXsize((ilImage *) theIlFile);
- ids->ysize = ilGetYsize((ilImage *) theIlFile);
- ids->zsize = ilGetCsize((ilImage *) theIlFile);
-
- /* In IL2.3, get format returns a char * rather than an int */
- typeName = ilFileImgGetImageFormat(theIlFile);
- if (strcmp(typeName, ilFIT_IMG) == 0) ids->subType = 1;
- else if (strcmp(typeName, ilTIFF_IMG) == 0) ids->subType = 2;
- else if (strcmp(typeName, ilSGI_IMG) == 0) ids->subType = 3;
- else ids->subType = 0;
-
- ilImageDelete((ilImage *) theIlFile);
- return TRUE;
-
- } else
- return FALSE;
- }
-
- /*
- * Read image file and subsample into memory slot.
- */
-
- /* Keep these for a while in case we need them... */
- #define PACK_RGBA_08(r, g, b, a) ((a)<<24 | (b)<<16 | (g)<<8 | (r))
- #define PACK_RGBA_16(r, g, b, a) (((a)&0xff00)<<16 | ((b)&0xff00)<<8 | \
- ((g)&0xff00) | ((r)&0xff00)>>8)
-
- int
- Iconify_IL(struct iconDirStruct *ids, unsigned long *ip) {
- char name_buf[PATH_MAX];
- ilFileImg *theIlFile;
- ilRotZoomImg *theRZImg;
- ilABGRImg *theABGR;
- ilConfig *theConfig;
- int returnCode;
- static int theChanList[] = {0, 1, 2, 3};
-
- if (ids->xsize <= 0 || ids->ysize <= 0 || ids->zsize <= 0) return TRUE;
-
- /* Defeat multi-threading, which interferes with our UI/reader operation */
- if (!unThreaded) {
- /* Not in libcil.a yet...
- ilMpSetMaxProcs(0, 0);
- */
- putenv("IL_COMPUTE_THREADS=0");
- putenv("IL_SPARE_THREADS=0");
- unThreaded = TRUE;
- }
-
- /* Open the image file, describe the zoom down */
- returnCode = TRUE;
- sprintf(name_buf, "%s/%s", theDirName, ids->name);
- if ((theIlFile = ilOpenImgFile(name_buf, "r")) == NULL) return FALSE;
- theRZImg = ilRotZoomImgCreate((ilImage *) theIlFile, 0.0, 1.0, 1.0,
- ilNoFlip, ilNearNb);
- ilRotZoomImgSizeToFit(theRZImg, ids->ixsize, ids->iysize, FALSE);
- theABGR = ilABGRImgCreate((ilImage *) theRZImg);
-
- /* Configure the icon pixels and get them */
- theConfig = ilConfigCreate(ilUChar, ilInterleaved, 4, NULL, 0,
- ilLowerLeftOrigin, (ilColorModel) 0);
- if (
- ilGetTile((ilImage *) theABGR, 0, 0, ids->ixsize, ids->iysize, ip,
- theConfig)
- != ilOKAY) returnCode = FALSE;
-
- ilConfigDelete(theConfig);
- ilImageDelete((ilImage *) theABGR);
- ilImageDelete((ilImage *) theRZImg);
- ilImageDelete((ilImage *) theIlFile);
- return returnCode;
- }
-
-
- char *
- Info_IL(struct iconDirStruct *ids, char *buf) {
- int colormap;
-
- switch (ids->subType) {
- case 1: sprintf(buf, "FIT format image"); break;
- case 2: sprintf(buf, "TIFF format image"); break;
- case 3: sprintf(buf, "SGI format image"); break;
- default: sprintf(buf, "ImageVision format image"); break;
- }
-
- return buf;
- }
-
- void
- Open_IL(struct iconDirStruct *ids) {
- char buf[PATH_MAX+64];
- char *cmd;
-
- /* Defeat multi-threading, which interferes with our UI/reader operation */
- if (!unThreaded) {
- /* Not in libcil.a yet...
- ilMpSetMaxProcs(0, 0);
- */
- putenv("IL_COMPUTE_THREADS=0");
- putenv("IL_SPARE_THREADS=0");
- unThreaded = TRUE;
- }
-
- /* What to do on double-click of icon - Execute env var or imgview! */
- if ((cmd = getenv("IBROWSE_IL_OPEN_CMD")) != NULL)
- /* Execute contents of Environment variable */
- ;
-
- else if (useIconFiles)
- /* Browsing from icon files. Don't try to open an image file. */
- return;
-
- else
- sprintf(cmd = buf, "/usr/sbin/imgview %s/%s &", theDirName, ids->name);
-
- system(cmd);
- }
-